namespace iScadaFBD
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    [Serializable]
    public abstract class DrawObject
    {
        private System.Drawing.Color color;
        private Rectangle fbRect;
        private uint id;
        private static System.Drawing.Color lastUsedColor = System.Drawing.Color.Black;
        private static int lastUsedPenWidth = 1;
        private iScadaFBD.GlobalParam.ObjectType objectType;
        private string objName;
        private int penWidth = 1;
        private bool selected;

        public virtual void Draw(Graphics g, DrawArea drawArea)
        {
        }

        public virtual void DrawTracker(Graphics g, DrawArea drawArea)
        {
            if (this.Selected)
            {
                SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
                if (drawArea.Focused)
                {
                    brush.Color = System.Drawing.Color.Black;
                }
                else
                {
                    brush.Color = System.Drawing.Color.Gray;
                }
                for (int i = 1; i <= this.HandleCount; i++)
                {
                    g.FillRectangle(brush, this.GetHandleRectangle(i));
                }
                brush.Dispose();
            }
        }

        public void GenerateID(iScadaFBD.GlobalParam.ObjectType type)
        {
            int num;
            int num2 = new Random((int) DateTime.Now.Ticks).Next(0x2710, 0x186a0);
            switch (type)
            {
                case iScadaFBD.GlobalParam.ObjectType.FunctionBlock:
                    num = 0xd3;
                    break;

                case iScadaFBD.GlobalParam.ObjectType.Connection:
                    num = 0xd4;
                    break;

                default:
                    num = 0xf4;
                    break;
            }
            int num3 = (num * 0x186a0) + num2;
            this.id = (uint) num3;
        }

        public virtual Point GetHandle(int handleNumber)
        {
            return new Point(0, 0);
        }

        public virtual Cursor GetHandleCursor(int handleNumber)
        {
            return Cursors.Default;
        }

        public virtual Rectangle GetHandleRectangle(int handleNumber)
        {
            Point handle = this.GetHandle(handleNumber);
            return new Rectangle(handle.X - 3, handle.Y - 3, 7, 7);
        }

        public virtual int HitTest(Point point)
        {
            return -1;
        }

        protected void Initialize()
        {
            this.color = lastUsedColor;
            this.penWidth = LastUsedPenWidth;
        }

        public virtual bool IntersectsWith(Rectangle rectangle)
        {
            return false;
        }

        public virtual void Move(int deltaX, int deltaY)
        {
        }

        public virtual void MoveHandleTo(Point point, int handleNumber)
        {
        }

        public virtual void Normalize()
        {
        }

        public virtual bool PointInObject(Point point)
        {
            return false;
        }

        [Browsable(false)]
        public System.Drawing.Color Color
        {
            get
            {
                return this.color;
            }
            set
            {
                this.color = value;
            }
        }

        [Browsable(true), Description("对象的位置与尺寸"), Category("位置尺寸")]
        public Rectangle FBRect
        {
            get
            {
                return this.fbRect;
            }
            set
            {
                this.fbRect = value;
            }
        }

        [Browsable(false)]
        public virtual int HandleCount
        {
            get
            {
                return 0;
            }
        }

        [Browsable(false)]
        public uint ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        [Browsable(false)]
        public static System.Drawing.Color LastUsedColor
        {
            get
            {
                return lastUsedColor;
            }
            set
            {
                lastUsedColor = value;
            }
        }

        [Browsable(false)]
        public static int LastUsedPenWidth
        {
            get
            {
                return lastUsedPenWidth;
            }
            set
            {
                lastUsedPenWidth = value;
            }
        }

        [Browsable(false)]
        public iScadaFBD.GlobalParam.ObjectType ObjectType
        {
            get
            {
                return this.objectType;
            }
            set
            {
                this.objectType = value;
            }
        }

        [Browsable(false)]
        public string ObjName
        {
            get
            {
                return this.objName;
            }
            set
            {
                this.objName = value;
            }
        }

        [Browsable(false)]
        public int PenWidth
        {
            get
            {
                return this.penWidth;
            }
            set
            {
                this.penWidth = value;
            }
        }

        [Browsable(false)]
        public bool Selected
        {
            get
            {
                return this.selected;
            }
            set
            {
                this.selected = value;
            }
        }
    }
}

